package com.rd.student.jiaji.class3.wangyanbo.day0829;

public class Test2 {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int i=0;
        int j=0;
        int k=0;
        double m;
        int[] result=new int[((nums1.length+nums2.length)/2)+1];
        while (i<=nums1.length-1&&j<=nums2.length-1&&k<=((nums1.length+nums2.length)/2)) {
            if (nums1[i] <= nums2[j]) {
                result[k] = nums1[i];
                i++;
            } else {
                result[k] = nums2[j];
                j++;
            }
            k++;
        }
        while (i<nums1.length&&k<=((nums1.length+nums2.length)/2)){result[k]=nums1[i];k++;i++;}
        while (j<nums2.length&&k<=((nums1.length+nums2.length)/2)){result[k]=nums2[j];k++;j++;}
        if((nums1.length+nums2.length)%2==0){m=(double)(result[result.length-1]+result[result.length-2])/2;}else {m=result[result.length-1];}
        return m;
    }
}
